import pymysql
import json
import time

db = pymysql.Connect(
    host='localhost',
    port=3306,
    user='root',
    password='DRsXT5ZJ6Oi55LPQ',
    db='teach',
    charset='utf8'
)

with open("E:/php/teaching/baiduregion/area.json",'r', encoding='UTF-8') as file:
    while True:
        cursor = db.cursor()
        line = file.readline()
        line_my = line.strip()
        line_dict = json.loads(line_my[0:-1])
        sql = "INSERT INTO region(code, parent_code, name, level, latitude, longitude) VALUES(%s, %s, %s, %s, %s, %s) "
        cursor.execute(sql, (int(line_dict['code']), int(line_dict['parentCode']), line_dict['name'], int(line_dict['level']), line_dict['latitude'], line_dict['longitude']))
        time.sleep(0.1)
print('exit')
